
// F. Chaxel 2010

#ifndef I2C_H
#define I2C_H

#include "IO.h"

#include "IO.h"

#define KERNEL_MODE_DRIVER 0
#define USER_MODE_DRIVER 1

class I2C:public Object
{
	
	private :
		int fd_i2c;
		IO *I2C_CLKLINE;
		IO *I2C_DATALINE;
		int Mode;

	private :
		int i2c_getbit(void);
		void i2c_dir_out(void);
		void i2c_dir_in(void);
		void i2c_data(int state);
		void i2c_clk(int state); 
		unsigned char i2c_inbyte(int islast);
		void i2c_start(void);
		void i2c_stop(void);
		int i2c_outbyte(unsigned char x); 


	public:
		I2C(int Mode);

		unsigned char ReadByte(unsigned char slave, unsigned char reg);
		long ReadLong(unsigned char slave, unsigned char reg);
		void Read_two_Long(unsigned char slave, unsigned char reg, long *val1, long *val2);
		int WriteByte(unsigned char slave, unsigned char reg, unsigned char val);
		int WriteWord(unsigned char slave, unsigned char reg, unsigned short val);
		

};

#endif
